
// 1.登陆密码格式是否正确
// 2.登陆密码程度显示
// 3.设置登录密码与确认登陆密码(确保一致)

window.addEventListener('load', function () {

    // 手机号格式
    var reg_user = /^[\u4e00-\u9fa5]{2, 4}$/;    //2-4个中文字符正则
    var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;    //11位手机号码正则
    var display = document.querySelector('.display');
    var display_icon = document.querySelector(".display_icon");

    var tel = document.querySelector('.tel');
    tel.addEventListener('keyup', function () {
        if (tel.value == "") {
            display.className = "error";
            display.innerHTML = "手机号码格式不正确,请重新输入";
            display_icon.className = "error_icon";

        } else if (!reg_tel.test(tel.value)) {
            display.className = "error";
            display_icon.className = "error_icon";
            display.innerHTML = "手机号码格式不正确,请重新输入";
        }
        else {
            display.className = "success";
            display.innerHTML = "手机号码格式输入正确";
            display_icon.className = "success_icon";
        }
    })

    // 账号密码格式
    var landing = document.querySelector("#landing");
    var password_icon = document.querySelector("#password_icon");
    var password_text = document.querySelector("#password_text");
    var safe = document.querySelector(".safe");
    var degree = safe.querySelectorAll("em");

    var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{8,30}');
    var regex1 = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}');
    var regex2 = new RegExp('(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9]).{8,30}');

    landing.addEventListener("keyup", function () {
        for (var i = 0; i < degree.length; i++) {
            degree[i].className = "";
        }
        password_text.innerHTML = "";
        password_text.className = "";
        password_icon.className = "";
        if (landing.value != "") {

            for (var i = 0; i < degree.length; i++) {
                degree[i].className = "";
            }
            password_text.innerHTML = "密码格式不正确,请重新输入";
            password_text.className = "error";
            password_icon.className = "error_icon";

            if (regex.test(landing.value)) {
                for (var i = 0; i < degree.length; i++) {
                    degree[i].className = "";
                }
                degree[0].className = "ruo";
                password_text.innerHTML = "密码格式正确";
                password_text.className = "success";
                password_icon.className = "success_icon";

                // alert("您的密码复杂度太低（密码中必须包含字母、数字），请及时改密码！");
            }

            if (regex1.test(landing.value)) {
                for (var i = 0; i < degree.length; i++) {
                    degree[i].className = "";
                }
                degree[1].className = "zhong";
                password_text.innerHTML = "密码格式正确";
                password_text.className = "success";
                password_icon.className = "success_icon";
                // alert("您的密码复杂度中等（密码中必须包含字母、数字、特殊字符），请及时改密码！");
            }

            if (regex2.test(landing.value)) {
                for (var i = 0; i < degree.length; i++) {
                    degree[i].className = "";
                }
                degree[2].className = "qiang";
                password_text.innerHTML = "密码格式正确";
                password_text.className = "success";
                password_icon.className = "success_icon";
                // alert("您的密码复杂度很强（密码中必须包含大小写字母、数字、特殊字符），请及时改密码！");
            }
        }
    })


    // 两个密码输入是否相同
    var Confirm = document.querySelector("#Confirm");
    var Confirm_icon = document.querySelector("#Confirm_icon");
    var Confirm_text = document.querySelector("#Confirm_text");

    Confirm.addEventListener("keyup", function () {
        if (Confirm.value == landing.value) {
            Confirm_text.innerHTML = "两次密码输入正确";
            Confirm_text.className = "success";
            Confirm_icon.className = "success_icon";
        }
        else {
            Confirm_text.innerHTML = "您两次输入的密码不同,请重试";
            Confirm_text.className = "error";
            Confirm_icon.className = "error_icon";
        }
    })
    // 随机生成数字
    var min = 1000;
    var max = 9999;

    function mynumber(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    var number = mynumber(min, max);
    var Sms = this.document.querySelector("#Sms");
    var Sms_icon = this.document.querySelector("#Sms_icon");
    var Sms_text = this.document.querySelector("#Sms_text")
    Sms.addEventListener("keyup", function () {
        if (Sms.value == number) {
            Sms_text.setAttribute('index', "success");
        }
        else {
            Sms_text.setAttribute('index', "error");
        }
    })

    // 短信认证
    var sent_btn = document.querySelector(".sent_btn");
    sent_btn.addEventListener("click", function () {
        console.log(number);
        if (display.className == "success") {
            sent_btn.disabled = true;

            var num = 120;
            var time = setInterval(function () {
                num--;
                if (num != 0) {
                    sent_btn.innerHTML = num + "s后重新获取";
                }
                else {
                    sent_btn.disabled = false;
                    console.log(sent_btn.disabled);
                    sent_btn.innerHTML = "120s后重新获取";
                    clearInterval(time);
                }
            }, 1000);
        }
        else {
            alert("请输入正确手机号");
        }
    })



})